from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')
from web_base.base_page import BasePage
from page_object.login_page import Login


class Asset(BasePage):
    url = r'/bsams/front/asset/asset_list.do'
    # 新增定位
    add_btn_loc = (By.CLASS_NAME, 'button_true')
    add_title_loc = (By.ID, 'title')
    add_providerId_loc = (By.ID, 'providerId')
    add_storageId_loc = (By.ID, 'storageId')
    add_ok_loc = (By.CLASS_NAME, 'button_fujian.margin')

    def asset_add(self, title, providerId, storageId):
        self.open()
        self.ele_click(self.add_btn_loc)
        self.input_ele(self.add_title_loc, title)
        self.ele_select(self.add_providerId_loc, providerId)
        self.ele_select(self.add_storageId_loc, storageId)
        self.ele_click(self.add_ok_loc)
        sleep(3)
        text = self.get_alert_text()
        self.alert_click()
        return text

    def asset_mod(self):
        pass

    def asset_query(self):
        pass

    def asset_lend(self):
        pass

    def asset_return(self):
        pass


if __name__ == '__main__':
    title = '联想小新01'
    providerId = '维信科技发展有限公司'
    storageId = '电脑设备库'

    chrome_location = r'E:\python\chrome\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)

    login = Login(driver)
    login.login()

    asset = Asset(driver)
    text = asset.asset_add(title, providerId, storageId)
    print(text)

    driver.quit()
